package com.jhon.yinji.lichuanvip.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jhon.yinji.lichuanvip.R;
import com.jhon.yinji.lichuanvip.bean.Shipin;

import org.xutils.common.util.LogUtil;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by yinji on 2016/7/14.
 */
public class MyAutoScrollAdapter extends PagerAdapter {
    private List<Shipin> shipins;
    private ImageView iv_img;
    private TextView tv_shadow;

    public MyAutoScrollAdapter(List<Shipin> shipins) {
        this.shipins = shipins;
    }

    @Override
    public int getCount() {
        return shipins.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Shipin shipin = shipins.get(position);
        View view= LayoutInflater.from(container.getContext()).inflate(R.layout.item_ad,null,false);
        iv_img = (ImageView) view.findViewById(R.id.iv_img);
        tv_shadow = (TextView) view.findViewById(R.id.tv_shadow);
        tv_shadow.setText(shipin.getTitle());
        x.image().bind(iv_img,shipin.getImgUrl());
        container.addView(view);
        return view;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
